package com.hckjsec.official.filters;

import com.hckjsec.common.filter.RepeatedlyRequestWrapper;
import com.hckjsec.common.utils.StringUtils;
import org.springframework.http.MediaType;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@WebFilter(filterName = "officialFilter",urlPatterns = {"/official/api/*"})
public class OfficialFilter implements Filter {
    @Override
    public void doFilter(ServletRequest rquest, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        ServletRequest requestWrapper = null;
        if (rquest instanceof HttpServletRequest && StringUtils.equalsAnyIgnoreCase(rquest.getContentType(),
                MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_JSON_UTF8_VALUE))
        {
            requestWrapper = new RepeatedlyRequestWrapper((HttpServletRequest) rquest, response);
        }
        System.out.println("进入公司网站过滤器======="+((RepeatedlyRequestWrapper) requestWrapper).getRequestURI());
        if (null == requestWrapper)
        {
            chain.doFilter(rquest, response);
        }
        else
        {
            chain.doFilter(requestWrapper, response);
        }
    }
}
